<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>Junit测试 | Celts</title><meta name="author" content="PaulGeorge"><meta name="copyright" content="PaulGeorge"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="写在前面在最开始的时候，我做程序的时候通常都是在实现一个功能后启动整个项目，然后对此功能进行自测，但是随着项目的体量主键庞大后，测试的时间效率反而越来越低了，那么有没有不启动项目就可以进行专项功能测试的方法呢？ 当然是有的啦，单元测试（Junit testing）就很好的解决了上述的问题。">
<meta property="og:type" content="article">
<meta property="og:title" content="Junit测试">
<meta property="og:url" content="https://curry3035.gitee.io/posts/38653/index.html">
<meta property="og:site_name" content="Celts">
<meta property="og:description" content="写在前面在最开始的时候，我做程序的时候通常都是在实现一个功能后启动整个项目，然后对此功能进行自测，但是随着项目的体量主键庞大后，测试的时间效率反而越来越低了，那么有没有不启动项目就可以进行专项功能测试的方法呢？ 当然是有的啦，单元测试（Junit testing）就很好的解决了上述的问题。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://curry3035.gitee.io/img/avatar.jpg">
<meta property="article:published_time" content="2021-02-13T13:58:58.000Z">
<meta property="article:modified_time" content="2021-10-26T17:08:32.563Z">
<meta property="article:author" content="PaulGeorge">
<meta property="article:tag" content="测试">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://curry3035.gitee.io/img/avatar.jpg"><link rel="shortcut icon" href="/img/ic.ico"><link rel="canonical" href="https://curry3035.gitee.io/posts/38653/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":false,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: PaulGeorge","link":"链接: ","source":"来源: Celts","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"top-right"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Junit测试',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-10-27 01:08:32'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/background.css"><link rel="stylesheet" href="/css/my.css"><meta name="generator" content="Hexo 5.4.2"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">64</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@img/mig2023/background05.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="Celts"><span class="site-name">Celts</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Junit测试</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-02-13T13:58:58.000Z" title="发表于 2021-02-13 21:58:58">2021-02-13</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-10-26T17:08:32.563Z" title="更新于 2021-10-27 01:08:32">2021-10-27</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E8%A7%84%E8%8C%83/">规范</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.1k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>8分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Junit测试"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h4 id="写在前面"><a href="#写在前面" class="headerlink" title="写在前面"></a>写在前面</h4><p>在最开始的时候，我做程序的时候通常都是在实现一个功能后启动整个项目，然后对此功能进行自测，但是随着项目的体量主键庞大后，测试的时间效率反而越来越低了，那么有没有不启动项目就可以进行专项功能测试的方法呢？</p>
<p>当然是有的啦，单元测试（Junit testing）就很好的解决了上述的问题。</p>
<span id="more"></span>



<h4 id="概念："><a href="#概念：" class="headerlink" title="概念："></a>概念：</h4><ol>
<li><p>单元测试（unit testing），是指对软件中的最小可测试单元进行检查和验证。在Java中单元测试的最小单元是类。</p>
</li>
<li><p>单元测试是开发者编写的一小段代码，用于检验被测代码的一个很小的、很明确的功能是否正确。执行单元测试，就是为了证明这 段代码的行为和我们期望是否一致。</p>
</li>
</ol>
<h4 id="实践"><a href="#实践" class="headerlink" title="实践"></a>实践</h4><h5 id="单元测试引用："><a href="#单元测试引用：" class="headerlink" title="单元测试引用："></a>单元测试引用：</h5><ol>
<li>通过spring initialize创建的Spring Boot项目会在Maven中自动携带很多starter依赖，其中包含了一个名为<code>spring-boot-starter-test</code>的依赖</li>
<li>Spring Boot中引入单元测试很简单，添加如下依赖（即<code>spring-boot-starter-test</code>依赖）</li>
</ol>
<figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-test<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">scope</span>&gt;</span>test<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>



<h5 id="单元测试的作用"><a href="#单元测试的作用" class="headerlink" title="单元测试的作用"></a>单元测试的作用</h5><p>在没有接触单元测试之前我们是怎么做测试的？一般有两个方法：</p>
<table>
<thead>
<tr>
<th align="center">方法</th>
<th align="center">弊端</th>
</tr>
</thead>
<tbody><tr>
<td align="center">1、启动整个项目，模拟正常的用户操作，点击之类的操作，调用API</td>
<td align="center">测试的时候需要启动整个项目</td>
</tr>
<tr>
<td align="center">2、在代码的某个地方写一个临时的入口，用于测试某个类或某个方法</td>
<td align="center">入口用完需要删除，否则会影响运行速度或效率</td>
</tr>
</tbody></table>
<p>我认为写单元测试的两个目的：</p>
<ol>
<li><p>保证或验证实现功能。</p>
</li>
<li><p>保护已经实现的功能不被破坏。</p>
</li>
</ol>
<h5 id="Service层的单元测试"><a href="#Service层的单元测试" class="headerlink" title="Service层的单元测试"></a>Service层的单元测试</h5><p>位置：Spring Boot中单元测试类写在src/test/java目录下；</p>
<p>举个荔枝：</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@SpringBootTest</span></span><br><span class="line"><span class="meta">@RunWith(SpringRunner.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">JUtServiceTest</span> &#123;</span><br><span class="line"><span class="meta">@Resource</span></span><br><span class="line"><span class="keyword">private</span> JUtService jUtService;</span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">conflictTime</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="type">DateTimeFormatter</span> <span class="variable">dtf</span> <span class="operator">=</span> DateTimeFormatter.ofPattern(<span class="string">&quot;yyyy-MM-dd&quot;</span>);</span><br><span class="line">        <span class="type">LocalDate</span> <span class="variable">start</span> <span class="operator">=</span> LocalDate.parse(<span class="string">&quot;2020-10-26&quot;</span>, dtf);</span><br><span class="line">        <span class="type">LocalDate</span> <span class="variable">end</span> <span class="operator">=</span> LocalDate.parse(<span class="string">&quot;2020-10-31&quot;</span>, dtf);</span><br><span class="line">        <span class="type">Integer</span> <span class="variable">integer</span> <span class="operator">=</span> XXXService.ConflictTime(<span class="string">&quot;10000001&quot;</span>, start, end);</span><br><span class="line">        Assert.assertThat(integer, Matchers.notNullValue());</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>注解解释：</p>
<ul>
<li><code>@SpringBootTest</code>：获取启动类，加载配置，寻找主配置启动类（被 @SpringBootApplication 注解的）</li>
<li> <code>@RunWith(SpringRunner.class)</code>：让JUnit运行Spring的测试环境,获得Spring环境的上下文的支持</li>
</ul>
<h5 id="Controller层的单元测试"><a href="#Controller层的单元测试" class="headerlink" title="Controller层的单元测试"></a>Controller层的单元测试</h5><p>位置：Spring Boot中单元测试类写在src/test/java目录下；</p>
<p>举个荔枝1：</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@SpringBootTest</span></span><br><span class="line"><span class="meta">@RunWith(SpringRunner.class)</span></span><br><span class="line"><span class="meta">@AutoConfigureMockMvc</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">JutControllerTest</span> &#123;</span><br><span class="line"><span class="meta">@Autowired</span></span><br><span class="line"><span class="keyword">private</span> MockMvc mockMvc;</span><br><span class="line"><span class="meta">@Before</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setUp</span><span class="params">()</span> <span class="keyword">throws</span> Exception &#123;</span><br><span class="line">       System.out.println(<span class="string">&quot;---------------start---------------&quot;</span>);</span><br><span class="line">       save();</span><br><span class="line">get();</span><br><span class="line">       System.out.println(<span class="string">&quot;================end================&quot;</span>);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>



<p>注解解释：</p>
<ul>
<li><code>@SpringBootTest</code>：获取启动类，加载配置，寻找主配置启动类（被 @SpringBootApplication 注解的）</li>
<li><code>@RunWith(SpringRunner.class)</code>：让JUnit运行Spring的测试环境,获得Spring环境的上下文的支持</li>
<li><code>@AutoConfigureMockMvc</code>：用于自动配置MockMvc,配置后MockMvc类可以直接注入,相当于new MockMvc </li>
<li><code>@Before</code>:初始化方法 ,对于每一个测试方法都要执行一次</li>
</ul>
<p>举个荔枝2：</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">get</span><span class="params">()</span> <span class="keyword">throws</span> Exception&#123;</span><br><span class="line">        <span class="type">ResultActions</span> <span class="variable">resultActions</span> <span class="operator">=</span> mockMvc.perform(MockMvcRequestBuilders</span><br><span class="line">                .get(<span class="string">&quot;/balabala/get&quot;</span>)</span><br><span class="line">                .param(<span class="string">&quot;id&quot;</span>, <span class="string">&quot;**********&quot;</span>)</span><br><span class="line">                .header(<span class="string">&quot;Authorization&quot;</span>, <span class="string">&quot;Bearer ********-****-****-****-************&quot;</span>)</span><br><span class="line">        );</span><br><span class="line">        resultActions.andReturn().getResponse().setCharacterEncoding(<span class="string">&quot;UTF-8&quot;</span>);</span><br><span class="line">        resultActions.andExpect(MockMvcResultMatchers.status().isOk()).andDo(print());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>注解解释：</p>
<ol>
<li><code>mockMvc.perform</code>：执行一个请求</li>
<li><code> MockMvcRequestBuilders.get(“/balabala/get”)</code>：构造一个请求，如果是<code>Post</code>请求使用.post方法</li>
<li><code> contentType(MediaType.APPLICATION_JSON_VALUE)</code>：代表发送端发送的数据格式是application/json;charset=UTF-8</li>
<li><code> accept(MediaType.APPLICATION_JSON)</code>：代表客户端希望接受的数据类型为application/json;charset=UTF-8</li>
<li><code> header(“Authorization”,“Bearer XXXX”)</code>：代表在报文头添加一些必须的信息，这里添加的是token</li>
<li><code> ResultActions.andExpect</code>：添加执行完成后的断言</li>
<li><code> ResultActions.andExpect(MockMvcResultMatchers.status().isOk())</code>：方法看请求的状态响应码是否为200如果不是则抛异常，测试不通过</li>
<li><code> ResultActions.andDo</code>：添加一个结果处理器，表示要对结果做点什么事情，比如此处使用print()：输出整个响应结果信息</li>
</ol>
<h4 id="JUnit-5测试"><a href="#JUnit-5测试" class="headerlink" title="JUnit 5测试"></a>JUnit 5测试</h4><h5 id="JUnit-生命周期"><a href="#JUnit-生命周期" class="headerlink" title="JUnit 生命周期"></a>JUnit 生命周期</h5><figure class="highlight csharp"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">JUnit5Test</span> &#123;</span><br><span class="line">    @BeforeAll</span><br><span class="line">    <span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">beforeAll</span>()</span> &#123;</span><br><span class="line">        System.<span class="keyword">out</span>.println(<span class="string">&quot;Before All&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @AfterAll</span><br><span class="line">    <span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">afterAll</span>()</span> &#123;</span><br><span class="line">        System.<span class="keyword">out</span>.println(<span class="string">&quot;After All&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @BeforeEach</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">before</span>()</span> &#123;</span><br><span class="line">        System.<span class="keyword">out</span>.println(<span class="string">&quot;Before&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @AfterEach</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">after</span>()</span> &#123;</span><br><span class="line">        System.<span class="keyword">out</span>.println(<span class="string">&quot;After&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Test</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">test1</span>()</span> &#123;</span><br><span class="line">        System.<span class="keyword">out</span>.println(<span class="string">&quot;Test 1&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Test</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">test2</span>()</span> &#123;</span><br><span class="line">        System.<span class="keyword">out</span>.println(<span class="string">&quot;Test 2&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>解释：</p>
<p>@Test：表示方法是测试方法；</p>
<p>@BeforeAll：表示被注解的方法应该在当前类的<font color=#008000>所有</font>@Test方法<font color=#008000>之前</font>执行；</p>
<p>@AfterAll：表示被注解的方法应该在当前类的<font color=#008000>所有</font>@Test方法<font color=#008000>之后</font>执行；</p>
<p>@BeforeEach：表示被注解的方法应在当前类的<font color=#FFA500>每个</font>@Test方法<font color=#FFA500>之前</font>执行；</p>
<p>@AfterEach：表示被注解的方法应在当前类的<font color=#FFA500>每个</font>@Test方法<font color=#FFA500>之后</font>执行；</p>
<h5 id="编写断言"><a href="#编写断言" class="headerlink" title="编写断言"></a>编写断言</h5><ol>
<li>简单断言</li>
</ol>
<table>
<thead>
<tr>
<th align="center">方法</th>
<th align="center">说明</th>
</tr>
</thead>
<tbody><tr>
<td align="center">assertEquals</td>
<td align="center">判断两个对象或两个原始类型是否相等</td>
</tr>
<tr>
<td align="center">assertNotEquals</td>
<td align="center">判断两个对象或两个原始类型是否不相等</td>
</tr>
<tr>
<td align="center">assertSame</td>
<td align="center">判断两个对象引用是否指向同一个对象</td>
</tr>
<tr>
<td align="center">assertNotSame</td>
<td align="center">判断两个对象引用是否指向不同的对象</td>
</tr>
<tr>
<td align="center">assertTrue</td>
<td align="center">判断给定的布尔值是否为 true</td>
</tr>
<tr>
<td align="center">assertFalse</td>
<td align="center">判断给定的布尔值是否为 false</td>
</tr>
<tr>
<td align="center">assertNull</td>
<td align="center">判断给定的对象引用是否为 null</td>
</tr>
<tr>
<td align="center">assertNotNull</td>
<td align="center">判断给定的对象引用是否不为 null</td>
</tr>
</tbody></table>
<p>举个荔枝：</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">void</span> <span class="title function_">testAssertion</span><span class="params">()</span> &#123;</span><br><span class="line">    assertEquals(<span class="number">10</span>, <span class="number">10</span>);</span><br><span class="line">    assertTrue(<span class="literal">true</span>);</span><br><span class="line">    assertEquals(<span class="number">100</span>, <span class="number">100</span>, <span class="string">&quot;两个数相等&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>前面断言失败，后面不会继续执行</p>
</blockquote>
<ol start="2">
<li>数组断言</li>
</ol>
<figure class="highlight csharp"><table><tr><td class="code"><pre><span class="line">@Test</span><br><span class="line">@DisplayName(<span class="string">&quot;array assertion&quot;</span>)</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">array</span>()</span> &#123;</span><br><span class="line">    assertArrayEquals(<span class="keyword">new</span> <span class="built_in">int</span>[]&#123;<span class="number">1</span>, <span class="number">2</span>&#125;, <span class="keyword">new</span> <span class="built_in">int</span>[] &#123;<span class="number">1</span>, <span class="number">2</span>&#125;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>组合断言</li>
</ol>
<figure class="highlight csharp"><table><tr><td class="code"><pre><span class="line">@Test</span><br><span class="line">@DisplayName(<span class="string">&quot;assert all&quot;</span>)</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">all</span>()</span> &#123;</span><br><span class="line"> assertAll(<span class="string">&quot;Math&quot;</span>,</span><br><span class="line">    () -&gt; assertEquals(<span class="number">2</span>, <span class="number">1</span> + <span class="number">1</span>),</span><br><span class="line">    () -&gt; assertTrue(<span class="number">1</span> &gt; <span class="number">0</span>)</span><br><span class="line"> );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="4">
<li>异常断言</li>
</ol>
<figure class="highlight csharp"><table><tr><td class="code"><pre><span class="line">@Test</span><br><span class="line">@DisplayName(<span class="string">&quot;异常测试&quot;</span>)</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">exceptionTest</span>()</span> &#123;</span><br><span class="line">    ArithmeticException exception = assertThrows(</span><br><span class="line">        <span class="comment">//扔出断言异常</span></span><br><span class="line">        ArithmeticException.<span class="keyword">class</span>, () -&gt; System.<span class="keyword">out</span>.println(<span class="number">1</span> % <span class="number">0</span>));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="5">
<li>超时断言</li>
</ol>
<figure class="highlight csharp"><table><tr><td class="code"><pre><span class="line">@Test</span><br><span class="line">@DisplayName(<span class="string">&quot;超时测试&quot;</span>)</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">timeoutTest</span>()</span> &#123;</span><br><span class="line">    <span class="comment">//如果测试方法时间超过1s将会异常</span></span><br><span class="line">    assertTimeout(Duration.ofMillis(<span class="number">1000</span>), () -&gt; Thread.sleep(<span class="number">500</span>));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="6">
<li>快速断言</li>
</ol>
<figure class="highlight csharp"><table><tr><td class="code"><pre><span class="line">@Test</span><br><span class="line">@DisplayName(<span class="string">&quot;fail&quot;</span>)</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">shouldFail</span>()</span> &#123;</span><br><span class="line"> 	fail(<span class="string">&quot;This should fail&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h5 id="常用注解"><a href="#常用注解" class="headerlink" title="常用注解"></a>常用注解</h5><p>显示名称【@DisplayName】</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@DisplayName(&quot;A special test case&quot;)</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">DisplayNameDemo</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="meta">@DisplayName(&quot;Custom test name containing spaces&quot;)</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">testWithDisplayNameContainingSpaces</span><span class="params">()</span> &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="meta">@DisplayName(&quot;╯°□°）╯&quot;)</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">testWithDisplayNameContainingSpecialCharacters</span><span class="params">()</span> &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="meta">@DisplayName(&quot;😱&quot;)</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">testWithDisplayNameContainingEmoji</span><span class="params">()</span> &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>禁用测试【@Disabled】</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Disabled</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">DisabledTestDemo</span> &#123;</span><br><span class="line">    <span class="meta">@Test</span> <span class="comment">//@Disabled</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">testDisabled</span><span class="params">()</span> &#123;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>重复测试【@RepeatedTest】</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">RepeatedTestDemo</span> &#123;</span><br><span class="line">    <span class="meta">@RepeatedTest(10)</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">testRepeated10Times</span><span class="params">()</span> &#123;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>附带标签【@RepeatedTest】</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Tag(&quot;taggedTest&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TagDemo</span> &#123;</span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="meta">@Tag(&quot;taggedTest1&quot;)</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">testWithTag1</span><span class="params">()</span> &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="meta">@Tag(&quot;taggedTest2&quot;)</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">testWithTag2</span><span class="params">()</span> &#123;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>嵌套测试【@Nested】</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@DisplayName(&quot;外层测试&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">NestedDemo</span> &#123;</span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">testOuter</span><span class="params">()</span> &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Nested</span></span><br><span class="line">    <span class="meta">@DisplayName(&quot;内层测试&quot;)</span></span><br><span class="line">    <span class="keyword">class</span> <span class="title class_">InnerTestDemo</span> &#123;</span><br><span class="line">        <span class="meta">@Test</span></span><br><span class="line">        <span class="keyword">void</span> <span class="title function_">testInner</span><span class="params">()</span> &#123;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="工作使用"><a href="#工作使用" class="headerlink" title="工作使用"></a>工作使用</h4><p>因为 Test 单元测试一般用来检验某个模块的特定功能，然后通过断言来验证其结果是否达到了我们的预期。</p>
<p>但是如果是使用的数据库测试库中的数据来进行验证只能够保证当时的正确性，一旦其他人修改了测试库中的数据，那么就会导致测试单元的不通过。</p>
<p>所以，为了避免上述问题，也为了写出一次测试，随时可测的的单元测试代码，我们需要自己伪造数据来帮助我们对功能的验证，我选择使用 <code>@Transactional</code> 和 <code>@Rollback</code> 注解。</p>
<p><strong>举个荔枝</strong></p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@SpringBootTest</span></span><br><span class="line"><span class="meta">@AutoConfigureMockMvc</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">ASEMobileRedisApplicationTests</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> MockMvc mockMvc;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@BeforeEach</span></span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">setUp</span><span class="params">()</span> &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;Before All&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="meta">@Transactional</span></span><br><span class="line">    <span class="meta">@Rollback</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">contextLoads</span><span class="params">()</span> <span class="keyword">throws</span> Exception &#123;</span><br><span class="line">        <span class="comment">// saveTest (造数据), 测试完毕后 Rollback (回滚)</span></span><br><span class="line">        saveTest();</span><br><span class="line">        queryTest();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="meta">@DisplayName(&quot;添加用户&quot;)</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">saveTest</span><span class="params">()</span> <span class="keyword">throws</span> Exception &#123;</span><br><span class="line">        <span class="type">String</span> <span class="variable">stringJson</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">String</span>(Files.readAllBytes(Paths.get(<span class="string">&quot;src&quot;</span>, <span class="string">&quot;test&quot;</span>, <span class="string">&quot;java&quot;</span>, <span class="string">&quot;com&quot;</span>, <span class="string">&quot;ase&quot;</span>, <span class="string">&quot;mobile&quot;</span>, <span class="string">&quot;User.json&quot;</span>)));</span><br><span class="line">        <span class="type">String</span> <span class="variable">jsonString</span> <span class="operator">=</span> JSON.toJSONString(stringJson);</span><br><span class="line">        <span class="comment">// 构建请求</span></span><br><span class="line">        mockMvc.perform(MockMvcRequestBuilders</span><br><span class="line">                .post(<span class="string">&quot;/test/post&quot;</span>)</span><br><span class="line">                .content(jsonString)</span><br><span class="line">                .header(<span class="string">&quot;Authorization&quot;</span>, <span class="string">&quot;Bearer ********-****-****-****-************&quot;</span>)</span><br><span class="line">                .contentType(MediaType.APPLICATION_JSON_VALUE) <span class="comment">//代表发送端发送的数据格式是 application/json;charset=UTF-8</span></span><br><span class="line">                .accept(MediaType.APPLICATION_JSON)) <span class="comment">//代表客户端希望接受的数据类型为 application/json;charset=UTF-8</span></span><br><span class="line">                .andDo(print())</span><br><span class="line">                .andExpect(status().isOk())</span><br><span class="line">                .andExpect(MockMvcResultMatchers.jsonPath(<span class="string">&quot;$.code&quot;</span>).value(<span class="string">&quot;200&quot;</span>))</span><br><span class="line">                .andExpect(MockMvcResultMatchers.jsonPath(<span class="string">&quot;$.data&quot;</span>).value(<span class="string">&quot;1&quot;</span>))</span><br><span class="line">                .andReturn();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="meta">@DisplayName(&quot;查询用户&quot;)</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">queryTest</span><span class="params">()</span> <span class="keyword">throws</span> Exception &#123;</span><br><span class="line">        <span class="type">String</span> <span class="variable">name</span> <span class="operator">=</span> <span class="string">&quot;tom&quot;</span>;</span><br><span class="line">        <span class="comment">// 构建请求</span></span><br><span class="line">        mockMvc.perform(MockMvcRequestBuilders</span><br><span class="line">                .post(<span class="string">&quot;/test/get&quot;</span>)</span><br><span class="line">                .param(<span class="string">&quot;name&quot;</span>, name)</span><br><span class="line">                .contentType(MediaType.APPLICATION_JSON_VALUE)</span><br><span class="line">                .accept(MediaType.APPLICATION_JSON))</span><br><span class="line">                .andDo(print())</span><br><span class="line">                .andExpect(status().isOk())</span><br><span class="line">                .andExpect(MockMvcResultMatchers.jsonPath(<span class="string">&quot;$.code&quot;</span>).value(<span class="string">&quot;200&quot;</span>))</span><br><span class="line">                .andExpect(MockMvcResultMatchers.jsonPath(<span class="string">&quot;$.data&quot;</span>).value(<span class="string">&quot;xxx&quot;</span>))</span><br><span class="line">                .andReturn();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://curry3035.gitee.io">PaulGeorge</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://curry3035.gitee.io/posts/38653/">https://curry3035.gitee.io/posts/38653/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://curry3035.gitee.io" target="_blank">Celts</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E6%B5%8B%E8%AF%95/">测试</a></div><div class="post_share"><div class="social-share" data-image="/img/avatar.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/1627/" title="如何将Sass编译成CSS"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">如何将Sass编译成CSS</div></div></a></div><div class="next-post pull-right"><a href="/posts/13521/" title="Vue系列--Webpack"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Vue系列--Webpack</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">PaulGeorge</div><div class="author-info__description">很多事情就像是旅行一样，当你决定要出发的时候，最困难的那部分其实就已经完成了</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">64</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/PaulGeorge123"><i class="fab fa-github"></i><span>GitHub URL</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/PaulGeorge123" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%86%99%E5%9C%A8%E5%89%8D%E9%9D%A2"><span class="toc-number">1.</span> <span class="toc-text">写在前面</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%A6%82%E5%BF%B5%EF%BC%9A"><span class="toc-number">2.</span> <span class="toc-text">概念：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%9E%E8%B7%B5"><span class="toc-number">3.</span> <span class="toc-text">实践</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E5%BC%95%E7%94%A8%EF%BC%9A"><span class="toc-number">3.1.</span> <span class="toc-text">单元测试引用：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E7%9A%84%E4%BD%9C%E7%94%A8"><span class="toc-number">3.2.</span> <span class="toc-text">单元测试的作用</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Service%E5%B1%82%E7%9A%84%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95"><span class="toc-number">3.3.</span> <span class="toc-text">Service层的单元测试</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Controller%E5%B1%82%E7%9A%84%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95"><span class="toc-number">3.4.</span> <span class="toc-text">Controller层的单元测试</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#JUnit-5%E6%B5%8B%E8%AF%95"><span class="toc-number">4.</span> <span class="toc-text">JUnit 5测试</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#JUnit-%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-number">4.1.</span> <span class="toc-text">JUnit 生命周期</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E7%BC%96%E5%86%99%E6%96%AD%E8%A8%80"><span class="toc-number">4.2.</span> <span class="toc-text">编写断言</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E6%B3%A8%E8%A7%A3"><span class="toc-number">4.3.</span> <span class="toc-text">常用注解</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B7%A5%E4%BD%9C%E4%BD%BF%E7%94%A8"><span class="toc-number">5.</span> <span class="toc-text">工作使用</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/47231/" title="POI读取Excel问题">POI读取Excel问题</a><time datetime="2023-04-11T01:00:00.000Z" title="发表于 2023-04-11 09:00:00">2023-04-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/8422/" title="Excel大文件的上传">Excel大文件的上传</a><time datetime="2023-04-10T01:00:00.000Z" title="发表于 2023-04-10 09:00:00">2023-04-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/55119/" title="每日一面--Files工具类">每日一面--Files工具类</a><time datetime="2023-01-01T01:00:00.000Z" title="发表于 2023-01-01 09:00:00">2023-01-01</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/34600/" title="面试一下--JUC入门">面试一下--JUC入门</a><time datetime="2022-09-10T01:00:00.000Z" title="发表于 2022-09-10 09:00:00">2022-09-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/16284/" title="每日一面--字符流和字节流">每日一面--字符流和字节流</a><time datetime="2022-07-01T01:00:00.000Z" title="发表于 2022-07-01 09:00:00">2022-07-01</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@img/mig2023/background05.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By PaulGeorge</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></body></html>